using System;

namespace Seagull.Events
{
    public struct RegistrationToken : IEquatable<RegistrationToken>
    {
        public static readonly RegistrationToken Empty = default(RegistrationToken);

        internal readonly int Token;

        public RegistrationToken(int token)
        {
            Token = token;
        }

        public bool IsEmpty
        {
            get { return this == Empty; }
        }

        #region Equality Members

        public bool Equals(RegistrationToken other)
        {
            return other.Token == Token;
        }

        public override bool Equals(object obj)
        {
            if(ReferenceEquals(null, obj))
                return false;
            if(obj.GetType() != typeof(RegistrationToken))
                return false;
            return Equals((RegistrationToken)obj);
        }

        public override int GetHashCode()
        {
            return Token;
        }

        public static bool operator ==(RegistrationToken left, RegistrationToken right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(RegistrationToken left, RegistrationToken right)
        {
            return !left.Equals(right);
        }

        #endregion

        public override string ToString()
        {
            return string.Format("Token value: {0}", Token);
        }
    }
}